﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CrystalDecisions.Shared;
using CrystalDecisions.CrystalReports.Engine;
using Microsoft.Reporting.WinForms;
using BUS;
namespace GUI
{
    public partial class frmInBaoCao : Form
    {
        public frmInBaoCao()
        {
            InitializeComponent();

        }

        public int MaHD
        {
            set;
            get;
        }

        //public void SetDBLogonForReport(CrystalDecisions.Windows.Forms.CrystalReportViewer rptObj)
        //{
        //    ConnectionInfo CnnInfo = new ConnectionInfo();
        //    System.Configuration.ConfigurationSettings.AppSettings["DataSource"].ToString();
        //    CnnInfo.ServerName = new System.Configuration.ConfigurationSettings.AppSettings["DataSource"].ToString();
        //    CnnInfo.DatabaseName = new System.Configuration.ConfigurationSettings.AppSettings["CSDL"].ToString();
        //    CnnInfo.UserID = new System.Configuration.ConfigurationSettings.AppSettings["UserID"].ToString();
        //    CnnInfo.Password = new System.Configuration.ConfigurationSettings.AppSettings["Password"].ToString();

        //    TableLogOnInfos tableLogOnInfos = rptObj.LogOnInfo;
        //    foreach (TableLogOnInfo tableLogOnInfo in tableLogOnInfos)
        //    {
        //        tableLogOnInfo.ConnectionInfo = CnnInfo;
        //    }
        //}

        private void frmInBaoCao_Load(object sender, EventArgs e)
        {
           // //SetDBLogonForReport(crystalReportViewer1);
           // rptCTHoaDon rp = new rptCTHoaDon();
           // rp.SetDataSource(BUS.CTHoaDonBUS.LayCTHoaDon(this.MaHD));
           //// MessageBox.Show(BUS.CTHoaDonBUS.LayCTHoaDon(this.MaHD).Tables[0].TableName);
           // ParameterValues a = new ParameterValues();
           // ParameterDiscreteValue b = new ParameterDiscreteValue();
           // b.Value = this.MaHD;
           // a.Add(b);
           // rp.DataDefinition.ParameterFields["maHD"].ApplyCurrentValues(a);
           // crystalReportViewer1.ReportSource = rp;
            DataTable dt = null;
            dt = CTHoaDonBUS.LayCTHoaDon(this.MaHD);
            reportViewer1.Reset();
            reportViewer1.LocalReport.ReportEmbeddedResource = "GUI.rptCTHoaDon.rdlc";
            reportViewer1.LocalReport.DataSources.Clear();
            Microsoft.Reporting.WinForms.ReportDataSource newDataSource = new Microsoft.Reporting.WinForms.ReportDataSource("DataSet1", dt);
            reportViewer1.LocalReport.DataSources.Add(newDataSource);
            List<ReportParameter> Parameters = new List<ReportParameter>();
            ReportParameter param = default(ReportParameter);
            param = new ReportParameter("maHD", this.MaHD.ToString());
            Parameters.Add(param);
            reportViewer1.LocalReport.SetParameters(Parameters);
            reportViewer1.RefreshReport();
            reportViewer1.LocalReport.DisplayName = "CTHoaDon";
            reportViewer1.SetDisplayMode(DisplayMode.PrintLayout);
            reportViewer1.ZoomMode = ZoomMode.PageWidth;
        }

        private void btnXemrpt_Click(object sender, EventArgs e)
        {
           
        }

    }
}
